<!-- xml version="1.0" encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>Latin Numerals</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="classics.css" rel="stylesheet" type="text/css">
</head>
<?php

try {
	$db = new PDO('sqlite:Latin.db3');
	$q = $db->query('SELECT * FROM numerals;');
	$nums = $q->fetchAll(PDO::FETCH_ASSOC);
	shuffle($nums);
	
	$vtab = "<caption>Latin Numerals</caption>\n";
	$vtab .= "<tr class=\"separate-above\"><td></td><th align=\"center\">Cardinal</th><th align=\"center\">Ordinal</th>";
	$vtab .= "<th align=\"center\">Distributive</th><th align=\"center\">Adverb</th></tr>\n";
	$txts = array();
	for($i = 0; $i <3; $i++ ) {
		$num = $nums[$i];
		$vtab .= "<tr>";
		foreach($num as $key => $value) {
			if ($key == 'roman') {
				$vtab .= "<th>$value</th>";
			} else {
				$vtab .= "<td align=\"center\">";
				foreach(explode("|", $value) as $word) {
					$txts[] = $word;
					$vtab = $vtab . "<input name=\"text".(count($txts) - 1)."\" type=\"text\" size=12>";
				}
				$vtab .= "</td>";
			}
		}
		$vtab .= "</tr>\n";
	}

	$db = NULL;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>


<script type="text/javascript">
function check() 
{

<?php
	for($i = 0, $nall = count($txts); $i < $nall; $i++) {
		print "if (document.n01.text".$i.".value=='".$txts[$i]."')\n{\n";
		print "\tdocument.n01.text".$i.".disabled=true;\n}\n";
	}
?>

}

function newWord() 
{
<?php
	for($i = 0, $nall = count($txts); $i < $nall; $i++) {
		print "document.n01.text".$i.".disabled=false;\n";
 		print "document.n01.text".$i.".value='';\n";
	}
?>
	location.reload();
}
</script>
<body>


<div id="container">
<div id="center">
<form name="n01" action="">
<table align="center">
<?php
	print $vtab;
?>
<tr class="separate-above">
	<td align="center" colspan=3><input name="Check" onclick="check()" value="Check" type="button"></td>
	<td align="center" colspan=2><input name="New Word" onclick="newWord()" value="New Word" type="button"></td>
</tr>
</table>
</form>


</div>
</div>

</body>
</html>
